package com.yj.change.hook;

import com.yj.change.Config;
import com.yj.change.db.HookDB;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.callbacks.XC_LoadPackage;


public class MainHook implements IXposedHookLoadPackage {

    private static boolean a(String paramString) {
        return (paramString.equals("android")) || (paramString.equals("com.android.providers.settings")) || (paramString.equals("com.android.server.telecom")) || (paramString.equals("com.android.location.fused")) || (paramString.equals("com.qualcomm.location"));
    }

    private static boolean b(String paramString) {
        return (paramString.startsWith("com.sonymobile")) || (paramString.startsWith("com.sonyericsson"));
    }

    @Override
    public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {

        XposedBridge.log("=========Loaded app:开始 ");
        ClassLoader classLoader = lpparam.classLoader;
        XposedBridge.log("=========Loaded app: " + lpparam.packageName);

        String packageName = lpparam.packageName;
        if (a(packageName) || b(packageName) || Config.packageName.equals(packageName)) {
            XposedBridge.log("=========Loaded app: 系统级应用");
            return;
        }
//        if (HookDB.getIntance().readHookApps().contains(packageName)) {
        XposedBridge.log("=========Loaded app: hook成功" + packageName);
        HookApp.hook(classLoader);
//        }
    }


}
